package org.esti.service.impl;

import org.esti.model.KnowledgeField;
import org.esti.model.dao.KnowledgeFieldDAO;
import org.esti.service.KnowledgeFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Artem Loginov (logart)
 */
@Service
public class KnowledgeFieldServiceImpl implements KnowledgeFieldService {

    @Autowired
    private KnowledgeFieldDAO dao;

    @Override
    public List<KnowledgeField> getAll() {
        return dao.getAllKnowledgeFields();
    }

    @Override
    public Map<Long, String> getKnowledgeFieldMap() {
        Map<Long, String> keyValues = new HashMap<Long, String>();
        List<KnowledgeField> knowledgeFields = dao.getAllKnowledgeFields();
        for (KnowledgeField knowledgeField : knowledgeFields) {
            keyValues.put(knowledgeField.getId(), knowledgeField.getName());
        }
        return keyValues;
    }

    @Override
    public KnowledgeField getKnowledgeFieldById(long id) {
        return dao.getKnowledgeFieldById(id);
    }

    @Override
    public KnowledgeField add(KnowledgeField knowledgeField) {
        return dao.add(knowledgeField);
    }

    @Override
    public void remove(long id) {
        dao.remove(id);
    }
}
